'/
' keycodes.bmx - version 1.04
' 
' Completely free to share, use, and do whatever with.
' Originally written 2010 by Anton Berlin.
'/

superstrict

const KEY_A_LC:int = 97,  KEY_B_LC:int = 98,  KEY_C_LC:int = 99,  KEY_D_LC:int = 100, KEY_E_LC:int = 101;
const KEY_F_LC:int = 102, KEY_G_LC:int = 103, KEY_H_LC:int = 104, KEY_I_LC:int = 105, KEY_J_LC:int = 106;
const KEY_K_LC:int = 107, KEY_L_LC:int = 108, KEY_M_LC:int = 109, KEY_N_LC:int = 110, KEY_O_LC:int = 111;
const KEY_P_LC:int = 112, KEY_Q_LC:int = 113, KEY_R_LC:int = 114, KEY_S_LC:int = 115, KEY_T_LC:int = 116;
const KEY_U_LC:int = 117, KEY_V_LC:int = 118, KEY_W_LC:int = 119, KEY_X_LC:int = 120, KEY_Y_LC:int = 121;
const KEY_Z_LC:int = 122;
const KEY_AA:int = 229, KEY_AA_LC:int = 197;
const KEY_AE:int = 228, KEY_AE_LC:int = 196;
const KEY_OE:int = 246, KEY_OE_LC:int = 214;

const KEY_EXCLAMATION:int = 33;

const KEY_COLON:int = 58;
const KEY_SEMICOLON:int = 59;
const KEY_QUOTES:int = 34;

const KEY_NUMBER:int = 35;
const KEY_HYPHEN:int = 45;
const KEY_DOLLAR:int = 36;
const KEY_AMPER:int = 38;
const KEY_APOSTR:int = 39;
const KEY_PLUS:int = 43;
const KEY_PERCENT:int = 37;
const KEY_ATSIGN:int = 64;
const KEY_UNDERSCR:int = 95;
const KEY_ASTERISK:int = 42;
const KEY_QUESTION:int = 63;
const KEY_LESSER:int = 60;
const KEY_EQUAL:int = 61;
const KEY_GREATER:int = 62;
const KEY_LEFTPAR:int = 40;
const KEY_RIGHTPAR:int = 41;
const KEY_VERTBAR:int = 124;
const KEY_SLASH:int = 47;
const KEY_SPACE:int = 32;

type keycodes

	'// -----------------------------------------------------------------------------------------------------------------
	'// See if an ascii value is a valid keyboard input, and if so, return it.
	'// -----------------------------------------------------------------------------------------------------------------
	function isWritableKey:byte(key:short, onlyNumbersAreValid:byte = false)

		local currentKeyStroke:byte = 0;
		
		'// Numbers.
		if (key = 48) currentKeyStroke = 48; ..
		else if (key = 49) currentKeyStroke = 49; ..
		else if (key = 50) currentKeyStroke = 50; ..
		else if (key = 51) currentKeyStroke = 51; ..
		else if (key = 52) currentKeyStroke = 52; ..
		else if (key = 53) currentKeyStroke = 53; ..
		else if (key = 54) currentKeyStroke = 54; ..
		else if (key = 55) currentKeyStroke = 55; ..
		else if (key = 56) currentKeyStroke = 56; ..
		else if (key = 57) currentKeyStroke = 57;
		
		if (onlyNumbersAreValid) ..
			return currentKeyStroke;
		
		'// Lowercase letters.
		if (key >= 65 and key <= 90) currentKeyStroke = key; ..
		else if (key = KEY_AA) currentKeyStroke = KEY_AA; ..
		else if (key = KEY_AE) currentKeyStroke = KEY_AE; ..
		else if (key = KEY_OE) currentKeyStroke = KEY_OE;
		
		'// Uppercase letters.
		if (key >= 97 and key <= 122) currentKeyStroke = key; ..
		else if (key = KEY_AA_LC) currentKeyStroke = KEY_AA_LC; ..
		else if (key = KEY_AE_LC) currentKeyStroke = KEY_AE_LC; ..
		else if (key = KEY_OE_LC) currentKeyStroke = KEY_OE_LC;
		
		'// Special keys.
		if (key = 44)                  currentKeyStroke = 44; ..
		else if (key = 46)             currentKeyStroke = 46; ..
		else if (key = KEY_EXCLAMATION) currentKeyStroke = KEY_EXCLAMATION; ..
		else if (key = KEY_QUOTES)      currentKeyStroke = KEY_QUOTES; ..
		else if (key = KEY_COLON)       currentKeyStroke = KEY_COLON; ..
		else if (key = KEY_SEMICOLON)   currentKeyStroke = KEY_SEMICOLON; ..
		else if (key = 191)             currentKeyStroke = 191; ..
		else if (key = KEY_NUMBER)      currentKeyStroke = KEY_NUMBER; ..
		else if (key = KEY_HYPHEN)      currentKeyStroke = KEY_HYPHEN; ..
		else if (key = KEY_DOLLAR)      currentKeyStroke = KEY_DOLLAR; ..
		else if (key = KEY_AMPER)       currentKeyStroke = KEY_AMPER; ..
		else if (key = KEY_APOSTR)      currentKeyStroke = KEY_APOSTR; ..
		else if (key = KEY_PLUS)        currentKeyStroke = KEY_PLUS; ..
		else if (key = KEY_PERCENT)     currentKeyStroke = KEY_PERCENT; ..
		else if (key = KEY_ATSIGN)      currentKeyStroke = KEY_ATSIGN; ..
		else if (key = KEY_UNDERSCR)    currentKeyStroke = KEY_UNDERSCR; ..
		else if (key = KEY_ASTERISK)    currentKeyStroke = KEY_ASTERISK; ..
		else if (key = KEY_QUESTION)    currentKeyStroke = KEY_QUESTION; ..
		else if (key = KEY_LESSER)      currentKeyStroke = KEY_LESSER; ..
		else if (key = KEY_EQUAL)       currentKeyStroke = KEY_EQUAL; ..
		else if (key = KEY_GREATER)     currentKeyStroke = KEY_GREATER; ..
		else if (key = KEY_LEFTPAR)     currentKeyStroke = KEY_LEFTPAR; ..
		else if (key = KEY_RIGHTPAR)    currentKeyStroke = KEY_RIGHTPAR; ..
		else if (key = KEY_VERTBAR)     currentKeyStroke = KEY_VERTBAR;
		
		return currentKeyStroke;

	end function

end type
